package com.ifacebox.client.tools.utils;

/**
 * @author Znn
 * @date 2021/1/17 21:50
 */
public class ThreadUtils {
    public static final String THREAD_NAME = "Thread-Utils";
    public static final int ONE_SECONDS = 1000;

    public static void run(Runnable run) {
        run(run, THREAD_NAME);
    }

    public static void run(Runnable run, String name) {
        newThread(run, name).start();
    }

    public static Thread newThread(Runnable run) {
        return newThread(run, THREAD_NAME);
    }

    public static Thread newThread(Runnable run, String name) {
        return new Thread(run, name) {{
            setDaemon(true);
        }};
    }

    public static void sleepOneSecond() {
        sleepSecond(1);
    }

    public static void sleepSecond(long seconds) {
        sleep(ONE_SECONDS * seconds);
    }

    public static void sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (Exception e) {
        }
    }
}
